import config from "@/config";
export default {
  // 存储
  setItem(key,val){
    let storage = this.getStorage();
    storage[key] = val;
    window.localStorage.setItem(config.namespace,JSON.stringify(storage));
  },
  // 查询
  getItem(key){
    return this.getStorage()[key]
  },
  // 获取值
  getStorage(){
    return JSON.parse(window.localStorage.getItem(config.namespace) || "{}");
  },
  // 删除某个变量
  clearItem(key){
    let storage = this.getStorage()
    delete storage[key]
    window.localStorage.setItem(config.namespace,JSON.stringify(storage))
  },
  // 清空
  clearAll(){
    window.localStorage.clear()
  }
}